#include <iostream>
#include <fstream>

#include "run_test.h"

#include "function.h"
#include "ZFunction.h"
#include "griewank_function.h"
#include "rosenbrock_function.h"
#include "shekel_function.h"
#include "zakharov_function.h"

void test_Simp(int argc, char *argv[ ])
{
  char File1[80]; // used for ZFunction only
  char File2[80]; // used for ZFunction only
  int seed;
  double TempStart, TempStep, TempEnd;
  double SuccessRatio;
  int    StepNumber; // Nmd
  int	   NSample;	  // Nmc number of samples for each run
  double StepLength; // = 0.01; //1e-2;
  int NEachTempRun; // number of runs for each temperature
  int N; // number of degrees of freedom

  if (argc == 13)
  {
    // required content of input arguments
    //
    // argv[1]     seed
    // argv[2]     temperature start
    // argv[3]     temperature step
    // argv[4]     temperature end
    // argv[5]     metropolis success ratio
    // argv[6]     N_md    (StepNumber)
    // argv[7]     N_mc    (NSample)
    // argv[8]    start step length (StepLength)
    // argv[9]    N_runs  (NEachTempRun)
    // argv[10]    the number of dimensions
    // argv[11]     zmatrix
    // argv[12]     inf data file

    seed = atoi(argv[1]);
    TempStart = atof(argv[2]);
    TempStep = atof(argv[3]);
    TempEnd = atof(argv[4]);
    SuccessRatio = atof(argv[5]);
    StepNumber = atoi(argv[6]);
    NSample = atoi(argv[7]);	 
    StepLength = atof(argv[8]); 
    NEachTempRun = atoi(argv[9]);
    N = atoi(argv[10]);
    strcpy_s(File1, 80, argv[11]);
    strcpy_s(File2, 80, argv[12]);
  }
  
  else if (argc == 1)
  {
    ifstream file("input/params_hmc.txt");

    if (! file)
    {
      cout << "Cannot open params.in\n";
      exit(1);
    }

    file >> seed >> TempStart >> TempStep
      >> TempEnd >> SuccessRatio
      >> StepNumber >> NSample >> StepLength
      >> NEachTempRun >> N >> File1 >> File2;

    file.close();
  }
  else
  {
    cout << "Incorrect input.\n";
    exit(1);
  }

  cout << "-------------------" << endl
       << "|     Simplex     |" << endl
       << "-------------------" << endl;

  Function *Zfunc = new ZFunction(N, File1, File2);
  //Function *grieFunc = new GriewankFunction(N);
  //Function *rosenFunc = new RosenbrockFunction(numDim);
  //Function *shekelFunc = new ShekelFunction(N);
  //Function *zakFunc = new ZakharovFunction(numDim);

  cout << "Dimension: " << N << endl << endl;

  run_Simp(argc, argv, Zfunc, string("output/ZfuncMolecule/Simplex/"), N);
  //run_Simp(argc, argv, grieFunc, string("output/Griewank/"), N);
  //run_Simp(argc, argv, rosenFunc, string("output/Rosenbrock/"), numDim);
  //run_Simp(argc, argv, shekelFunc, string("output/Shekel/"), N);
  //run_Simp(argc, argv, zakFunc, string("output/Zakharov/"), numDim);
}